#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool cmp(vector<int> a, vector<int> b){
	return a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]);
}

int main(){
	int n;
	cin>>n;
	vector<vector<int>> envelopes(n, vector<int>(2));
	for(int i=0;i<n;i++){
		cin>>envelopes[i][0]>>envelopes[i][1];
	}

	sort(envelopes.begin(), envelopes.end(), cmp);

        vector<int> f(n, 1);
        for (int i = 1; i < n; ++i) {
            for (int j = 0; j < i; ++j) {
                if (envelopes[j][1] < envelopes[i][1]) {
                    f[i] = max(f[i], f[j] + 1);
                }
            }
        }
        cout<<*max_element(f.begin(), f.end())<<endl;
    return 0;
} 
